/**
 * vision 2.0; author ：姜友瑶;
 */
(function($) {
	$.fn.extend({
		invoke : function(url, callback) {
			$this = this;
			var url = basePath + "/" + url;
			// 是否开启遮罩
			if (this.attr("c")) {
				layer.load(2, {
					time : 10 * 1000,
					shade : [ 0.4, '#aeaeae' ]
				});
			}
			$.ajax({
				type : "post",
				url : url,
				data : this.attr("gs_parameter"),
				async : this.attr("a"),
				success : function(result) {
					// 全局异常处理器发出的错误信息
					if (result.status == "err") {
						layer.closeAll('loading');
						layer.msg(result.info, {
							icon : 2
						});
						return null;
					} else {
						$this.attr("result", result);
						layer.closeAll('loading');
						if (callback != null) {
							callback($this);
						}
					}
				}
			});
		},

		getRowCount : function() {
			return this.attr("result").dataList.length;
		},
		// * @param key列名
		getValue : function(key) {
			var temp = "";
			try {
				temp = eval("this.attr('result')." + key);
			} catch (e) {
				console.log('getValue执行失败');
			}
			return temp;
		},
		/**
		 * @param mapName游标名称
		 * @param index
		 *            角标
		 * @param key列名
		 * @returns
		 */
		getString : function(index, key) {
			var temp = "";
			try {
				temp = eval("this.attr('result').dataList[" + index + "]."+ key );
				if(!temp){
					temp="";
				}
			} catch (e) {
				console.log('getString执行失败');
			}
			return temp;
		},
		getDate : function(index, key) {
			var temp = "";
			try {
				temp = eval("this.attr('result').dataList[" + index + "]['"
						+ key + "']");
			    var date = new Date(temp);
			    if(!temp){
					return "";
				}else{
					return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes();
				}
			} catch (e) {
				console.log('getString执行失败');
			}
			return temp;
		}
	});
	$.extend({
		/** 初始化过程请求参数 */
		AjaxProxy : function(initparam) {
			// 初始化参数
			var process = {
				gs_parameter : {},
				a : true,
				c : true
			};
			// initJSON 格式
			// { p:[ 1,2,3 ], a : true , c : false }
			if (initparam == undefined) {
				var initparam = {};
			}
			if (initparam.p) {
				process.gs_parameter = $.extend(process.gs_parameter,
						initparam.p);
			}
			process = $.extend(process, initparam);
			delete process.p;
			return $(process);
		}

	});

})(jQuery);
